home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / earthlink / nscomm / java40.jar / java / lang / Thread.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-03  |  5.4 KB  |  293 lines

  1. package java.lang;
  2.  
  3. import netscape.debug.Debugger;
  4. import netscape.debug.ThreadHook;
  5. import netscape.debug.ThreadState;
  6.  
  7. public class Thread implements Runnable {
  8.    private char[] name;
  9.    private int priority;
  10.    private Thread threadQ;
  11.    private int PrivateInfo;
  12.    private int eetop;
  13.    private boolean single_step;
  14.    private boolean daemon = false;
  15.    private boolean stillborn = false;
  16.    private Runnable target;
  17.    private static Thread activeThreadQ;
  18.    private ThreadGroup group;
  19.    private static int threadInitNumber;
  20.    private ThreadHook hook;
  21.    private ThreadState debugState;
  22.    private boolean inDebugSuspend;
  23.    private int initial_stack_memory;
  24.    public static final int MIN_PRIORITY = 1;
  25.    public static final int NORM_PRIORITY = 5;
  26.    public static final int MAX_PRIORITY = 10;
  27.  
  28.    private static synchronized int nextThreadNum() {
  29.       return threadInitNumber++;
  30.    }
  31.  
  32.    public static native Thread currentThread();
  33.  
  34.    public static native void yield();
  35.  
  36.    public static native void sleep(long var0) throws InterruptedException;
  37.  
  38.    public static void sleep(long var0, int var2) throws InterruptedException {
  39.       if (var0 < 0L) {
  40.          throw new IllegalArgumentException("timeout value is negative");
  41.       } else if (var2 >= 0 && var2 <= 999999) {
  42.          if (var2 >= 500000 || var2 != 0 && var0 == 0L) {
  43.             ++var0;
  44.          }
  45.  
  46.          sleep(var0);
  47.       } else {
  48.          throw new IllegalArgumentException("nanosecond timeout value out of range");
  49.       }
  50.    }
  51.  
  52.    private void init(ThreadGroup var1, Runnable var2, String var3) {
  53.       this.init(var1, var2, var3, false);
  54.    }
  55.  
  56.    private void init(ThreadGroup var1, Runnable var2, String var3, boolean var4) {
  57.       Thread var5 = currentThread();
  58.       if (var1 == null) {
  59.          SecurityManager var6 = System.getSecurityManager();
  60.          if (var6 != null) {
  61.             var1 = var6.getThreadGroup();
  62.          }
  63.  
  64.          if (var1 == null) {
  65.             var1 = var5.getThreadGroup();
  66.          }
  67.       } else if (var4) {
  68.          var1.checkAccess();
  69.       }
  70.  
  71.       this.group = var1;
  72.       this.daemon = var5.isDaemon();
  73.       this.priority = var5.getPriority();
  74.       this.name = var3.toCharArray();
  75.       this.target = var2;
  76.       SecurityManager.enablePrivilege("UniversalThreadAccess");
  77.       this.setPriority(this.priority);
  78.       SecurityManager.revertPrivilege();
  79.       var1.add(this);
  80.    }
  81.  
  82.    public Thread() {
  83.       this.init((ThreadGroup)null, (Runnable)null, "Thread-" + nextThreadNum(), true);
  84.    }
  85.  
  86.    public Thread(Runnable var1) {
  87.       this.init((ThreadGroup)null, var1, "Thread-" + nextThreadNum(), true);
  88.    }
  89.  
  90.    public Thread(ThreadGroup var1, Runnable var2) {
  91.       this.init(var1, var2, "Thread-" + nextThreadNum(), true);
  92.    }
  93.  
  94.    public Thread(String var1) {
  95.       this.init((ThreadGroup)null, (Runnable)null, var1, true);
  96.    }
  97.  
  98.    public Thread(ThreadGroup var1, String var2) {
  99.       this.init(var1, (Runnable)null, var2, true);
  100.    }
  101.  
  102.    public Thread(Runnable var1, String var2) {
  103.       this.init((ThreadGroup)null, var1, var2, true);
  104.    }
  105.  
  106.    public Thread(ThreadGroup var1, Runnable var2, String var3) {
  107.       this.init(var1, var2, var3, true);
  108.    }
  109.  
  110.    public synchronized native void start();
  111.  
  112.    public void run() {
  113.       if (this.target != null) {
  114.          this.target.run();
  115.       }
  116.  
  117.    }
  118.  
  119.    private void exit() {
  120.       if (this.group != null) {
  121.          this.group.remove(this);
  122.          this.group = null;
  123.       }
  124.  
  125.       this.target = null;
  126.    }
  127.  
  128.    public final void stop() {
  129.       SecurityManager.enablePrivilege("UniversalThreadAccess");
  130.       this.stop(new ThreadDeath());
  131.    }
  132.  
  133.    public final synchronized void stop(Throwable var1) {
  134.       System.getSecurityManager().checkAccess(this, var1);
  135.       this.resume();
  136.       this.stop0(var1);
  137.    }
  138.  
  139.    public void interrupt() {
  140.       System.getSecurityManager().checkAccess(this);
  141.       this.interrupt0();
  142.    }
  143.  
  144.    public static boolean interrupted() {
  145.       return currentThread().isInterrupted(true);
  146.    }
  147.  
  148.    public boolean isInterrupted() {
  149.       return this.isInterrupted(false);
  150.    }
  151.  
  152.    private native boolean isInterrupted(boolean var1);
  153.  
  154.    public void destroy() {
  155.       throw new NoSuchMethodError();
  156.    }
  157.  
  158.    public final native boolean isAlive();
  159.  
  160.    public final void suspend() {
  161.       System.getSecurityManager().checkAccess(this);
  162.       if (Debugger.getDebugManager() == null) {
  163.          System.err.println("Warning: Thread.suspend() was called; Navigator deadlock might result");
  164.       }
  165.  
  166.       this.suspend0();
  167.    }
  168.  
  169.    public final void resume() {
  170.       System.getSecurityManager().checkAccess(this);
  171.       this.resume0();
  172.    }
  173.  
  174.    public final void setPriority(int var1) {
  175.       if (SecurityManager.isPrivilegeEnabled("UniversalThreadAccess")) {
  176.          System.getSecurityManager().checkAccess(this);
  177.          if (var1 <= 10 && var1 >= 1) {
  178.             if (var1 > this.group.getMaxPriority()) {
  179.                var1 = this.group.getMaxPriority();
  180.             }
  181.  
  182.             this.setPriority0(this.priority = var1);
  183.          } else {
  184.             throw new IllegalArgumentException();
  185.          }
  186.       }
  187.    }
  188.  
  189.    public final int getPriority() {
  190.       return this.priority;
  191.    }
  192.  
  193.    public final void setName(String var1) {
  194.       System.getSecurityManager().checkAccess(this);
  195.       this.name = var1.toCharArray();
  196.    }
  197.  
  198.    public final String getName() {
  199.       return String.valueOf(this.name);
  200.    }
  201.  
  202.    public final ThreadGroup getThreadGroup() {
  203.       return this.group;
  204.    }
  205.  
  206.    public static int activeCount() {
  207.       return currentThread().getThreadGroup().activeCount();
  208.    }
  209.  
  210.    public static int enumerate(Thread[] var0) {
  211.       return currentThread().getThreadGroup().enumerate(var0);
  212.    }
  213.  
  214.    public native int countStackFrames();
  215.  
  216.    public final synchronized void join(long var1) throws InterruptedException {
  217.       long var3 = System.currentTimeMillis();
  218.       long var5 = 0L;
  219.       if (var1 < 0L) {
  220.          throw new IllegalArgumentException("timeout value is negative");
  221.       } else if (var1 == 0L) {
  222.          while(this.isAlive()) {
  223.             this.wait(0L);
  224.          }
  225.  
  226.       } else {
  227.          while(this.isAlive()) {
  228.             long var7 = var1 - var5;
  229.             if (var7 <= 0L) {
  230.                break;
  231.             }
  232.  
  233.             this.wait(var7);
  234.             var5 = System.currentTimeMillis() - var3;
  235.          }
  236.  
  237.       }
  238.    }
  239.  
  240.    public final synchronized void join(long var1, int var3) throws InterruptedException {
  241.       if (var1 < 0L) {
  242.          throw new IllegalArgumentException("timeout value is negative");
  243.       } else if (var3 >= 0 && var3 <= 999999) {
  244.          if (var3 >= 500000 || var3 != 0 && var1 == 0L) {
  245.             ++var1;
  246.          }
  247.  
  248.          this.join(var1);
  249.       } else {
  250.          throw new IllegalArgumentException("nanosecond timeout value out of range");
  251.       }
  252.    }
  253.  
  254.    public final void join() throws InterruptedException {
  255.       this.join(0L);
  256.    }
  257.  
  258.    public static void dumpStack() {
  259.       (new Exception("Stack trace")).printStackTrace();
  260.    }
  261.  
  262.    public final void setDaemon(boolean var1) {
  263.       System.getSecurityManager().checkAccess(this);
  264.       if (this.isAlive()) {
  265.          throw new IllegalThreadStateException();
  266.       } else {
  267.          this.daemon = var1;
  268.       }
  269.    }
  270.  
  271.    public final boolean isDaemon() {
  272.       return this.daemon;
  273.    }
  274.  
  275.    public void checkAccess() {
  276.       System.getSecurityManager().checkAccess(this);
  277.    }
  278.  
  279.    public String toString() {
  280.       return this.getThreadGroup() != null ? "Thread[" + this.getName() + "," + this.getPriority() + "," + this.getThreadGroup().getName() + "]" : "Thread[" + this.getName() + "," + this.getPriority() + "," + "" + "]";
  281.    }
  282.  
  283.    private native void setPriority0(int var1);
  284.  
  285.    private native void stop0(Object var1);
  286.  
  287.    private native void suspend0();
  288.  
  289.    private native void resume0();
  290.  
  291.    private native void interrupt0();
  292. }
  293.